﻿package code 
{
	import flash.display.MovieClip;
	import flash.events.*;
	
	public class Document extends MovieClip 
	{
		private var level;
		private var menu;
		private var player:Player;
		private var isVictory:Boolean;
		private var score:uint;
		private var numKills:uint;
		//private var 
		
		public function Document() 
		{
			isVictory = false;
			score = 0;
			numKills = 0;
			
			setupMenu();
			//level = new Level();
			//addChild(level);
			 
			//addEventListener(Event.ENTER_FRAME, onUpdate);
		}
		
		public function onUpdate(e:Event)
		{
			level.update();
		}
		
		public function setupMenu()
		{
			menu = new MenuFull();
			addChild(menu);
		}
		
		public function startGame():void
		{
			isVictory = false;
			score = 0;
			numKills = 0;
			
			level = new Level();
			addChild(level);
			 
			addEventListener(Event.ENTER_FRAME, onUpdate);
		}
		
		public function endGame():void
		{
			isVictory = level.getVictory();
			score = level.getScore();
			numKills = level.getKills();
			
			menu.gotoAndStop("StatsToMain");
			setStats(isVictory, score, numKills);
			
			level.closeLevel();
			removeEventListener(Event.ENTER_FRAME, onUpdate);
			removeChild(level);
		}
		
		
		// Sets the menu stats
		public function setStats(isVictory:Boolean, score:uint, numKills:uint)
		{
			if( isVictory )
				menu.statsMenu_inst.VictoryText.text = "Victory";
			else
				menu.statsMenu_inst.VictoryText.text = "Failure";
			menu.statsMenu_inst.ScoreText.text = score;
			menu.statsMenu_inst.KillsText.text = numKills;
		}
	}
}
